path(path,'../libs/publicMatlabLibs/');
datafileFolderPrefix= '../data/simResults/satPropError_';

dataFolderid = [0,3,4,5,6,8];
satData = {};
for sat = 1: 1
    satData{sat} = {};
    % for i = 1:length(dataFolderid)
    for  i  = 1: 99 % experiment times 
        dataFolder = strcat(datafileFolderPrefix,'mento_8_exp',num2str(i));
        satdatafile = strcat(dataFolder,'/sat',num2str(sat),'.mat');
        satData{sat}{i} = load(satdatafile);
    end
end
dataFolder = strcat(datafileFolderPrefix,num2str(dataFolderid(1)));
satdatafile = strcat(dataFolder,'/sat',num2str(1),'.mat');
realData = load(satdatafile);

realMean = realData.kineStateMeans(1:3,:);
realMean = realMean(:,1:50000);
expDataMean = zeros(3,50000,99);
for sat = 1:1
   for experiment = 1 : 99
        expDataMean(:,:,experiment) = satData{sat}{experiment}.kineStateMeans(1:3,:);
       
        % for i = 2:length(dataFolderid)
        %     comparedData = satData{sat}{i};
        %     comMean = comparedData.kineStateMeans(1:3,:);
        %     figure();
        %     plot(comMean'-realMean');
        % end
    end
end
timeTags = satData{sat}{1}.timeTags;
timeTags = (timeTags- timeTags(1))/86400;
expDataMeanMean  = mean(expDataMean,3);
expstd  = std(expDataMean,0,3);
plot(timeTags,realMean'-expDataMeanMean');
figure();
plot(timeTags,expstd');

% what about the covaiance for the forecast?
forecastCovs = realData.kineStateCovs;
figure();
plot(timeTags,sqrt(reshape(forecastCovs(1,1,1:50000),1,50000)));

% The realationship between forecast std and true std 
figure();
plot(timeTags,expstd(1,:)./sqrt(reshape(forecastCovs(1,1,1:50000),1,50000)));
hold on
plot(timeTags,expstd(2,:)./sqrt(reshape(forecastCovs(2,2,1:50000),1,50000)));
plot(timeTags,expstd(3,:)./sqrt(reshape(forecastCovs(3,3,1:50000),1,50000)));